package com.zzt.questionbanktotalmaneger.controller;

import com.zzt.questionbanktotalmaneger.bean.common.Result;
import com.zzt.questionbanktotalmaneger.bean.dto.UserDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class LoginController {
    @Autowired
    private RestTemplate template;

    @Value("${userManager.userServiceUrl}")
    private String userServiceUrl;

    @RequestMapping(value = "/login")
    public Result checkLogin(@RequestBody UserDTO dto){
        System.out.println(userServiceUrl+"login");
        System.out.println(dto);
        Result result= template.postForObject(userServiceUrl+"login",dto,Result.class);
        result.setToken("1515q");
        System.out.println(result);

        return result;
    }

    @RequestMapping("/findAllTest")
    public List<UserDTO> findAll(){
        return template.postForObject(userServiceUrl+"findAllUserTest",null,List.class);
    }
}
